//
//@File    :	15.8_error2.cpp
//@Time    :	2022/03/10 11:18:43
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	returning an error code
//

#include <iostream>
#include <cfloat>

bool hmean(double a,double b,double *ans);
int main()
{
    double x,y,z;

    std::cout<<"Enter two numters: ";
    while (std::cin>>x>>y)
    {
        if (hmean(x,y,&z))
        {
            std::cout<<"Harmonic mean od "<<x<<" and "<<y<<" is "<<z<<std::endl;
        }else{
            std::cout<<"One value should not be the negtive "<<"of the other try agin.\n";
            std::cout<<"Enter next set of numbers <q to quit>: ";
        }
    }
    std::cout<<"Bye!\n";
    system("pause");
    return 0;
}
//返回值为bool,结果写入ans指针所指内存中
bool hmean(double a,double b,double *ans){
    if (a==-b){
        *ans = DBL_MAX;
        return false;
    }else{
        *ans =  2.0*a*b/(a+b);
        return true;
    }
}